﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using PetaPoco;

namespace DAL.MySQL
{
    public class liuyanDAL
    {
        public Database db = DbScoure.DataBase();
        public liuyanEntity GetOne(int id)
        {
            return db.SingleOrDefault<liuyanEntity>("select * from liuyan where id=@0", id);
        }
        public List<liuyanEntity> GetList(string where, string order, params object[] args)
        {
            var list = db.Fetch<liuyanEntity>("select * from liuyan where 1=1 " + where + " order by " + order + " ,ID desc", args);
            return list;
        }

        public Page<liuyanEntity> GetPageList(int pagenum, int pagesize, string where, string order, params object[] args)
        {
            var pagelist = db.Page<liuyanEntity>(pagenum, pagesize, "select * from liuyan where 1=1 " + where + " order by " + order + " ,ID desc", args);
            return pagelist;
        }

        public int Update(object obj,int ID)
        {
             return db.Update("liuyan", "ID", obj, ID);
        }
        public liuyanEntity Save(liuyanEntity model)
        {
            db.Save("liuyan", "ID", model);
            return model;
        }

        public bool Del(int id)
        {
            try
            {
                db.Delete("liuyan", "ID", null, id);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public bool Del(liuyanEntity model)
        {
            try
            {
                db.Delete("liuyan", "ID", model);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
